﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;

namespace PTA.NET
{
    public partial class TracNghiem : Form
    {
        public TracNghiem()
        {
            InitializeComponent();
        }

        private void TracNghiem_KeyDown(object sender, KeyEventArgs e)
        {
            Console.WriteLine("KeyCode: " + e.KeyCode.ToString());
            //.WriteLine("KeyData: " + e.KeyData.ToString());

           
            if (e.KeyCode != Keys.F2 || e.KeyCode != Keys.F4)
            {
                e = null;
                
                return;
            }
            //if (e.KeyData == Keys.w)
            //Application.Exit();

        }

        public int STT = 1;
        string[] CauHoi;

        private void NhapTraLoi(string TraLoi)
        {
            Common.CustomerItem.QuestionList[STT].Answer = TraLoi;

            if (STT >= 568 || STT < 1)
            {
                btnDUNG.Visible = false;
                btnSAI.Visible = false;
                btnKHONG.Visible = false;

                lblCauHoi.Text = "Đã hoàn tất bài kiểm tra. Cám ơn " + Common.CustomerItem.CustomerName + ".";
            }

            HienThiCauHoi(++STT);            
        }

        private void HienThiCauHoi(int stt)
        {
            // Hien thi câu ke tiep
            if (STT <= 568 && STT >= 1)
            {
                lblCauHoi.Text = CauHoi[stt].Split('#')[1];
                lblTotalCauHoi.Text = stt.ToString() + "/567";
            }            
        }

        private void TracNghiem_Load(object sender, EventArgs e)
        {
            CauHoi = File.ReadAllLines("Data\\cauhoi.txt");
            //STT = 445;
            lblCauHoi.Text = CauHoi[STT].Split('#')[1];
            lblTotalCauHoi.Text = STT.ToString() + "/567";
        }

        private void btnDUNG_Click(object sender, EventArgs e)
        {
            NhapTraLoi("DUNG");
        }

        private void btnSAI_Click(object sender, EventArgs e)
        {
            NhapTraLoi("SAI");
        }

        private void btnKHONG_Click(object sender, EventArgs e)
        {
            NhapTraLoi("KHONG");
        }

        private void btnXuLy_Click(object sender, EventArgs e)
        {
            Password frmPass = new Password();
            frmPass.ShowDialog();
            if (frmPass.OK == "OK")
                this.Close();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            STT--;
            HienThiCauHoi(STT);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            STT++;
            HienThiCauHoi(STT);
        }

     

     
    }
}